(function () {
    chrome.storage.local.get(["type", "server_addr", "pwd"], function (items) {
        if (items.type == undefined) {
            var $radios = $('input[name="encrypt_type"]');
            if ($radios.is(':checked') === false) {
                $radios.filter('[value=aes]').prop('checked', true);
            }
        }
        if (items.server_addr = undefined) {
            $("#server").val("http://localhost:8888");
        }

        if (items.pwd == undefined) {
            $("#pwd").val("");
        }

        store();
    });

    $("#save").click(store());

    function store() {
        var type = $('input[name="encrypt_type"]:checked').val();
        var server_addr = $("#server").val();
        var pwd = $("#pwd").val();


        if (pwd == undefined || pwd == null || pwd == "")
            pwd = null;

        chrome.storage.local.set({"type": type, "server_addr": server_addr, "pwd": pwd});
    }
})();